{% extends 'base.html' %}
{% load static %}
{% block title %}用户管理 - 用户信息修改{% endblock %}
{% block content %}
<!-- 内容标题栏 -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-12">
              <h1 class="m-0 text-dark">用户管理</h1>
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/">首页</a></li>
              <li class="breadcrumb-item active">用户管理</li>
                <li class="breadcrumb-item active"><a href="{% url 'login:user_pwd_modify' %}">用户修改</a></li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /内容标题栏 -->
<section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-3"></div>
                <div class="col-md-6">
                    <div class="card card-info">      <!--蓝绿色标题背景-->
                        <div class="card-header">
                            <h3 class="card-title">用户信息修改</h3>
                        </div>
                        <form id="put" class="form" enctype="multipart/form-data" action="" method="post">
                        {% csrf_token %}
                        <div class="card-body">
                            {% for info in user_info %}
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">用户名<span class="text-danger">*</span></label>
                                <div class="col-sm-9">
                                    <input type="hidden" id="user_id" name="user_id" value="{{ info.id }}"/>
                                    <input  class="form-control" type="text" name="username" value="{{ info.username }}" readonly>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">邮箱地址<span class="text-danger">*</span></label>
                                <div class="col-sm-9">
                                    <input  class="form-control" type="text" name="email" id="email" value="{{ info.email }}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">手机号码<span class="text-danger">*</span></label>
                                <div class="col-sm-9">
                                    <input  class="form-control" type="text" name="mobile" id="mobile" value="{{ info.mobile }}">
                                </div>
                            </div>
                                <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">直属领导</label>
                                <div class="col-sm-9">
                                    <select class="form-control" id="direct_leader" name="direct_leader">
                                    <option style="display: none;" disabled selected>请选择直属领导</option>
                                    {% for user in direct_leader %}
                                    <option value="{{ user.username }}" {% ifequal user.username info.direct_leader %} selected{% endifequal %}>{{ user.username }}</option>
                                    {% endfor %}
                                    </select>
                                </div>
                            </div>
                                {% if request.user.is_superuser == 1 %}
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">部门</label>
                                <div class="col-sm-9">
                                    <select class="form-control" id="department" name="department" style="width: 100% !important;">
                                    <option style="display: none;" disabled selected>请选择部门</option>
                                    {% for group in Department_info %}
                                    <option value="{{ group.id }}" {% ifequal group.id info.department_id %} selected{% endifequal %}>{{ group.name }}</option>
                                    {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">职位</label>
                                <div class="col-sm-9">
                                    <select class="form-control" id="position" name="position" style="width: 100% !important;">
                                    <option style="display: none;" disabled selected>请选择职位</option>
                                    {% for j in all_position %}
                                    <option value="{{ j.id }}" {% ifequal j.id info.position_id %} selected{% endifequal %}>{{ j.name }}</option>
                                    {% endfor %}
                                    </select>
                                </div>
                            </div>
                            {% endif %}
                                {% if request.user.is_superuser == 1 %}
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">用户状态</label>
                                <div class="col-sm-9">
                                    <select class="form-control" name="is_active" id="is_active">
                                        <option value="1" {% ifequal info.is_active 1 %}selected{% endifequal %}>有效</option>
                                        <option value="0" {% ifequal info.is_active 0 %}selected{% endifequal %}>禁用</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">用户角色</label>
                                <div class="col-sm-9">
                                    <select class="form-control" name="role" id="role">
                                            <option style="display: none;" disabled selected>请选择</option>
                                            {% for role in role_info %}
                                            <option value="{{ role.id }}" {% ifequal role.id info.role_id %}selected{% endifequal %}>{{ role.name }}</option>
                                            {% endfor %}
                                    </select>
                                </div>
                            </div>
                                    <div id="is_charger_div" class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">部门负责人</label>
                                <div class="col-sm-9">
                                    <select class="form-control" id="is_charger" name="is_charger">
                                            <option value="1">是</option>
                                            <option value="0" selected>否</option>
                                    </select>
                                </div>
                            </div>
                                {% endif %}
                                {% if request.user.is_superuser == 1 %}
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-primary">超级管理员</label>
                                <div class="col-sm-9">
                                    <select class="form-control" name="is_superuser" id="is_superuser">
                                        <option value="1" {% ifequal info.is_superuser 1 %}selected{% endifequal %}>是</option>
                                        <option value="0" {% ifequal info.is_superuser 0 %}selected{% endifequal %}>否</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-success">重设密码</label>
                                <div class="col-sm-9">
                                    <input  class="form-control" type="password" id="pw1" name="pw1" onKeyUp="passwordChangeStatuss(this.value);" onBlur="passwordChangeStatuss(this.value);"><span></span>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-success">密码强度</label>
				                <div class="col-sm-9 layui-btn-group pwd-item ">
					                <label id="l" class="layui-btn layui-btn-primary" style="width: 33.34%;">低</label>
					                <label id="m" class="layui-btn layui-btn-primary " style="width: 33.3%;">中</label>
					                <label id="h" class="layui-btn layui-btn-primary" style="width: 33.3%;">高</label>
				                </div>
			                </div>
                            <div class="form-group row">
                                <label class="col-sm-3 col-form-label text-right text-success">确认密码</label>
                                <div class="col-sm-9 js-pw2">
                                    <input  class="form-control" type="password" id="pw2" name="pw2"><span></span>
                                </div>
                            </div>
                                {% endif %}
                        {% endfor %}
                        </div>
                        <div class="card-footer">
                            <input class="btn btn-info" type="submit" value="提交"/>
                        </div>
                        </form>
                    </div>
                </div>
        </div>
        </div>
</section>
{% block custom_js %}
    <script src="{% static 'static/js/check.js' %}"></script>
<script>
// 提交，FORM  ID
$("#put").submit(function () {
    var options = {
        success: showRespone,  //ajaxForm提交成功后，执行函数
        resetForm: false,      //执行完毕后是否重设表单
        datetype: 'json',      //数据类型
    }
    $("#put").ajaxSubmit(options);
    return false;
})

function showRespone(data) {
    if(data.status === 1){
        //操作成功
        layui.use('layer',function () {
            var layer=layui.layer;
            info = data.info
            layer.alert(info,{
                icon: 6,
                btn: '确定',
                skin: 'layer-ext-moon',
                yes: function () {
                    window.location.reload()
                },

            })
        })
    }else {
        //操作失败
        layui.use('layer',function () {
            var layer=layui.layer;
            info = data.info
            layer.alert(info,{
                icon: 5,
                skin: 'layer-ext-moon',
            })
        })
    }
}
</script>
{% endblock %}
{% endblock %}
